package com.jiukuaidao.zhulin.module.address;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiukuaidao.library.base.BaseActivity;
import com.jiukuaidao.library.widget.recyclerview.XRecyclerView;
import com.jiukuaidao.zhulin.R;
import com.jiukuaidao.zhulin.adapter.GainPlaceAdapter;
import com.jiukuaidao.zhulin.data.TaskProvider;
import com.jiukuaidao.zhulin.module.address.contract.GainPlaceContract;
import com.jiukuaidao.zhulin.module.address.presenter.GainPlacePresenter;

import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * Author : PaiTaSuo
 * Date : 2016/6/7
 * Description :
 */
public class SearchPlaceActivity extends BaseActivity<GainPlaceContract.Presenter> implements GainPlaceContract.View, View.OnClickListener {
    @BindView(R.id.titile_text)
    TextView mTitleText;
    @BindView(R.id.titile_left_imageview)
    ImageView mLeftImg;
    @BindView(R.id.search_place_recycle)
    XRecyclerView mPlaceRecycle;
    private String mTitleStr;
    private String mRegion;
    private String mCityCode;
    private GainPlaceAdapter mBaseAdapter;
    /**
     *  与GainPlaceActivity 共用adapter 用于区分
     */
    private String adapterType = "search";

    @Override
    protected View getTargetView() {
        return null;
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_search_place;
    }

    @Override
    protected void handleBundle(Bundle bundle) {
        mTitleStr = bundle.getString("addressStr");
        mRegion = bundle.getString("region");
        mCityCode = bundle.getString("cityCode");

    }

    @Override
    protected void init() {
        mTitleText.setText(mTitleStr);
        new GainPlacePresenter(TaskProvider.provideTasksRepository(this), this);
        mPresenter.startSuggestionSearch();
        setOnClickListener();

    }

    @Override
    public double getLongitude() {
        return 0;
    }

    @Override
    public double getLatitude() {
        return 0;
    }

    @Override
    public String getQuery() {
        return mTitleStr;
    }

    @Override
    public String getRegion() {
        return mRegion;
    }

    @Override
    public String getCityCode() {
        return mCityCode;
    }

    @Override
    public void placeList(List<Map<String, String>> list, String type) {
        mBaseAdapter = new GainPlaceAdapter(this, R.layout.item_search_place, list, mPlaceRecycle, type, adapterType);
        mPlaceRecycle.setLayoutManager(new LinearLayoutManager(this));
        mPlaceRecycle.setAdapter(mBaseAdapter);
        mPlaceRecycle.setPullRefreshEnabled(false);
        mPlaceRecycle.setLoadingMoreEnabled(false);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titile_left_imageview:
                finish();
                break;
        }
    }

    public void setOnClickListener() {
        mLeftImg.setOnClickListener(this);
    }
}
